package com.zhongyouyun.other.task;

import cn.hutool.core.util.ObjectUtil;
import com.zhongyouyun.job.TestJob;
import com.zhongyouyun.utils.SpringUtil;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;

import org.springframework.scheduling.quartz.QuartzJobBean;

import java.lang.reflect.Method;

@DisallowConcurrentExecution
public class BaseJob extends QuartzJobBean {

    private String className;
    private String methodName;
    private String businessParam;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        try {
            Class xclass = Class.forName(className);
            Method method = xclass.getDeclaredMethod(methodName);
            if (ObjectUtil.isNotEmpty(businessParam)) {
                method.invoke(xclass.newInstance(), businessParam);
            } else {
                method.invoke(xclass.newInstance());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public void setBusinessParam(String businessParam) {
        this.businessParam = businessParam;
    }


}
